<template>
  <el-card style="margin-bottom:20px;">
    <div slot="header" class="clearfix">
      <span>个人信息</span>
    </div>

    <div class="user-profile">
      <div class="text-center">
<!--        <el-upload
          class="upload-demo"
          action="https://jsonplaceholder.typicode.com/posts/"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload"
          :show-file-list="false"
        >
          <div slot="trigger">
            <pan-thumb class="point" :image="user.avatar" :height="'100px'" :width="'100px'" :hoverable="false">
              &lt;!&ndash;          <div>Hello</div>&ndash;&gt;
            </pan-thumb>
          </div>
        </el-upload>-->
        <userAvatar :user="user" />

      </div>
      <div class="box-center">
        <div class="user-name text-center">{{ user.realName }}</div>
        <div class="user-role text-center text-muted">{{ user.role }}</div>
      </div>
    </div>

    <div class="user-bio">
      <div class="user-education user-bio-section">
        <div class="user-bio-section-header"><i class="iconfont icon-ic_idcard" /><span>简介</span></div>
        <div class="user-bio-section-body">
          <div class="text-muted">
            <p v-if="user.description">{{ user.description }}</p>
            <p v-else class="gray">{{ (user.sex=== 2 ? '她' : '他') + '很懒，什么都没留下' }}</p>
          </div>
        </div>
      </div>

      <div class="user-skills user-bio-section">
        <!--        <div class="user-bio-section-header"><svg-icon icon-class="skill" /><span>Skills</span></div>-->
        <div class="user-bio-section-body font-13">
          <div class="progress-item solid-bottom">
            <i class="el-icon-user" />
            <span>用户名</span>
            <span class="fr">{{ user.username }}</span>
          </div>
          <div class="progress-item solid-bottom" v-if="user.email">
            <i class="el-icon-message" />
            <span>邮箱</span>
            <span class="fr">{{ user.email }}</span>
          </div>
          <div class="progress-item solid-bottom" v-if="user.phone">
            <i class="el-icon-phone" />
            <span>手机号</span>
            <span class="fr">{{ user.phone }}</span>
          </div>
          <div class="progress-item solid-bottom" v-if="user.superiorName">
            <i class="el-icon-phone" />
            <span>行政上级</span>
            <span class="fr">{{ user.superiorName }}</span>
          </div>
          <div class="progress-item solid-bottom" v-if="user.parent.some(o=> o.orgType === 3)">
            <i class="el-icon-s-check" />
            <span>所属角色</span>
            <span class="fr">{{ user.parent.filter(o=> o.orgType === 3).map(o=> o.orgName).join('、') }}</span>
          </div>
          <div class="progress-item solid-bottom" v-if="user.parent.some(o=> o.orgType === 2)">
            <svg-icon icon-class="tree" />
            <span>所属部门</span>
            <span class="fr">{{ user.parent.filter(o=> o.orgType === 2).map(o=> o.orgName).join('、') }}</span>
          </div>
          <div class="progress-item solid-bottom">
            <i class="el-icon-date" />
            <span>创建日期</span>
            <span class="fr">{{ user.createDt }}</span>
          </div>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script>
// import PanThumb from '@/components/PanThumb'
import userAvatar from './userAvatar'

export default {
  components: { /* PanThumb, */ userAvatar },
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          realName: null,
          email: null,
          avatar: null,
          phone: null,
          description: null,
          sex: null,
          superiorName: null,
          createDt: null,
          parent: []
        }
      }
    }
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw)
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    }
  }
}
</script>

<style lang="scss" scoped>
.box-center {
  margin: 0 auto;
  display: table;
}

.text-muted {
  color: #777;
}

.user-profile {
  .user-name {
    font-weight: bold;
  }

  .box-center {
    padding-top: 10px;
  }

  .user-role {
    padding-top: 10px;
    font-weight: 400;
    font-size: 14px;
  }

  .box-social {
    padding-top: 30px;

    .el-table {
      border-top: 1px solid #dfe6ec;
    }
  }

  .user-follow {
    padding-top: 20px;
  }
}
.progress-item {
  padding: 10px 0;
  font-size: 13px;
}
.user-bio {
  margin-top: 20px;
  color: #606266;

  span {
    padding-left: 4px;
  }

  .user-bio-section {
    font-size: 14px;
    padding: 15px 0;

    .user-bio-section-header {
      border-bottom: 1px solid #dfe6ec;
      padding-bottom: 10px;
      margin-bottom: 10px;
      font-weight: bold;
    }
  }
}
</style>
